package com.viphuli.util;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;
import baidumapsdk.demo.BaiduMapUtilByRacer;
import baidumapsdk.demo.BaiduMapUtilByRacer.LocateListener;
import baidumapsdk.demo.LocationBean;

import com.offroader.utils.ViewUtils;

/**
 * 地图工具类
 * 
 * @author li.li
 *
 */
public class MapUtils {
	
	/**
	 * 定位
	 * @param act
	 */
	public static void locate(Activity act) {

		locate(act, new LocateListener() {

			@Override
			public void onLocateSucceed(LocationBean locationBean) {
				ViewUtils.toast("当前城市：" + locationBean.city);
			}

			@Override
			public void onLocateFiled() {
				ViewUtils.toast("定位失败");
			}

			@Override
			public void onLocating() {
				ViewUtils.toast("正在获得位置信息");
			}
		});
	}
	
	/**
	 * 定位
	 * @param act
	 * @param textView
	 */
	public static void locate(Activity act, final TextView textView) {

		locate(act, new LocateListener() {

			@Override
			public void onLocateSucceed(LocationBean locationBean) {
				textView.setText(locationBean.city);
				textView.setVisibility(View.VISIBLE);
			}

			@Override
			public void onLocateFiled() {
				textView.setText("定位失败");
				textView.setVisibility(View.VISIBLE);
			}

			@Override
			public void onLocating() {
				textView.setText("定位中...");
				textView.setVisibility(View.VISIBLE);
			}
		});
	}
	
	/**
	 * 定位
	 * @param act
	 * @param locateListener
	 */
	public static void locate(Activity act, LocateListener locateListener) {
		BaiduMapUtilByRacer.locateByBaiduMap(act, 2000, locateListener);
	}

}
